/**
 * @param {number[]} scores
 * @param {number[][]} edges
 * @return {number}
 */
 var maximumScore = function(scores, edges) {
  if(edges.length === 0) return -1
  const g = {}
  for(const [x, y] of edges) {
    g[x] = g[x] || new Set()
    g[y] = g[y] || new Set()
    g[x].add(y)
    g[y].add(x)
  }
  let ans = -1
  for(let i = 0; i<scores.length; i++) {
    dfs(i, scores[i], [scores[i]], new Set().add(i))
  }
  return ans
  function dfs(s, v, path, used = new Set()) {
    if(used.size === 4) {
      ans = Math.max(ans, v)
      return
    }
    const last = path[path.length-1]
    for(const e of g[s] || []) {
      if(used.has(e) || (g[last] && !g[last].has(e))) continue
      used.add(e)
      dfs(e, v+scores[e], [...path, e],used)
      used.delete(e)
    }
  }
  function check(s) {
    const arr = [...s]
    for(let i = 1; i<4; i++) {
      if(!g[arr[i-1]].has(arr[i])) {
        return false
      }
    }
    return true
  }
};